'''sample_db.py --- drop all tables from ioks & create small sample ones'''

from db_utils import *
from db_classes import *


def main():
    cursor = get_cnxn().cursor()
    drop_tables(cursor)
    create_tables(cursor)
    create_sample_db(cursor)

def create_sample_db(cursor):
    #Add first site
    my_site = site(1, 'www.site1.ru')
    add_to_db(cursor, my_site)
    my_page0 = page(0, 1, 'www.site1.ru/index.php', 1, 1, '<html></html>')
    my_page1 = page(1, 1, 'www.site1.ru/contact.php', 1, 2, '<html></html>')
    my_page2 = page(2, 1, 'www.site1.ru/main.php', 1, 1, '<html></html>')
    add_to_db(cursor, my_page1)
    add_to_db(cursor, my_page2)
    add_to_db(cursor, my_page0)
    #Add second site
    my_site2 = site(2, 'www.site2.ru')
    add_to_db(cursor, my_site2)
    my_page3 = page(3, 2, 'www.site2.ru/index.php', 1, 1, '<html></html>')
    my_page4 = page(4, 2, 'www.site2.ru/contact.php', 1, 2, '<html></html>')
    my_page5 = page(5, 2, 'www.site2.ru/main.php', 1, 1, '<html></html>')
    add_to_db(cursor, my_page3)
    add_to_db(cursor, my_page4)
    add_to_db(cursor, my_page5)
    #Add link to first site
    link_to_1 = link(0, 0, 'site 1 main', 'site1')
    add_to_db(cursor, link_to_1)
    #Publicate link on second site
    link_place1 = page_to_link(3, 0, 1)
    link_place2 = page_to_link(4, 0, 1)
    add_to_db(cursor, link_place1)
    add_to_db(cursor, link_place2)
    cursor.execute('COMMIT')
    #Add keywords to base
    keyword_1 = keyword(0, 'a', '4')
    keyword_2 = keyword(1, 'b', '4')
    keyword_3 = keyword(2, 'c', '5')
    keyword_4 = keyword(3, 'd', '3')
    keyword_5 = keyword(4, 'e', '5')
    add_to_db(cursor, keyword_1)
    add_to_db(cursor, keyword_2)
    add_to_db(cursor, keyword_3)
    add_to_db(cursor, keyword_4)
    add_to_db(cursor, keyword_5)
    #Include some text on the pages
    p2k_1  = page_to_keyword(0, 0, 0.7) # index   - a
    p2k_2  = page_to_keyword(0, 1, 0.7) # index   - b
    p2k_3  = page_to_keyword(0, 2, 0.7) # index   - c
    p2k_4  = page_to_keyword(1, 2, 0.7) # contact - c
    p2k_5  = page_to_keyword(1, 3, 0.7) # contact - d
    p2k_6  = page_to_keyword(2, 0, 0.8) # main    - a
    p2k_7  = page_to_keyword(3, 1, 0.7) # index   - b
    p2k_8  = page_to_keyword(3, 3, 0.7) # index   - e
    p2k_9  = page_to_keyword(4, 0, 0.7) # contact - a
    p2k_10 = page_to_keyword(4, 2, 0.7) # contact - c
    p2k_11 = page_to_keyword(5, 2, 0.8) # main    - c
    add_to_db(cursor, p2k_1)
    add_to_db(cursor, p2k_2)
    add_to_db(cursor, p2k_3)
    add_to_db(cursor, p2k_4)
    add_to_db(cursor, p2k_5)
    add_to_db(cursor, p2k_6)
    add_to_db(cursor, p2k_7)
    add_to_db(cursor, p2k_8)
    add_to_db(cursor, p2k_9)
    add_to_db(cursor, p2k_10)
    add_to_db(cursor, p2k_11)
    cursor.execute('COMMIT')


if __name__ == '__main__':
    main()

